<template>
	<view class="myteam">
		<!-- 顶部导航 -->
		<diyNavBar value='我的团队' color='#4689FF'></diyNavBar>
		<view class="teambox">
			<view class="item" v-for="(item,index) in list" :key="index">
				<text class="money">{{item.num}}</text>
				<text class="title">{{item.title}}</text>
			</view>
		</view>
<!-- 		<view class="inputsearch">
			<input type="number" value="" placeholder="请输入id"/>
		</view> -->
		<view class="contentList">
			<view class="title">任务数据</view>
			<view class="itembox">
				<view class="item" v-for="(item,index) in contentList" :key="index">
					<view class="num">{{item.num}}</view>
					<view class="text">{{item.title}}</view>
				</view>
			</view>
		</view>
		<view class="dieList">
			<view class="tabrlist">
				<view class="item" v-for="(item,index) in tabsList" :key="index"
				:class="indexJudge == index?'hovercolor':''"
				@click="select(index)">
					{{item}}
				</view>
			</view>
			<scroll-view scroll-y="true" scroll-top='0' class="scroll">
				<block v-if="indexJudge != 2">
					<mescroll-body ref="mescrollRef" height='840rpx' @down="downCallback" @up="upCallback"
					 :up = "upOption" :down="downOption">
						<view class="item" v-for="(item,index) in taskList" :key="index">
							<view class="itemBlock">
								<view class="left">
									<image :src="$util.img(item.avatar)" mode=""></image>
									<view class="box">
										<view class="num">{{item.mobile}}
											<view class="txt" @click="packupSelect(index)">
												展开<view class="iconfont 
												icon-xiala1" :style="packupIndex == index && item.packupJudge?'':'transform: rotateZ(-90deg)'"></view>
											</view>
											<view class="txt" @click="packupSelect2()">
												等级<view class="iconfont 
												icon-xiala1" :style="openShow?'':'transform: rotateZ(-90deg)'"></view>
											</view>
										</view>
										<view class="id">ID：{{item.id}}</view>
									</view>
								</view>
								<view class="right">
									<view class="title">个人业绩</view>
									<view class="money">￥{{item.achievement_money}}元</view>
								</view>
							</view>
							<view class="bottomContent contentList" v-if="packupIndex == index && item.packupJudge">
								<view class="itembox">
									<view class="item itemhover">
										<view class="num">{{item.tjzcount}}</view>
										<view class="text">提交总任务</view>
									</view>
									<view class="item itemhover" >
										<view class="num">{{item.jjzcount}}</view>
										<view class="text">拒绝总任务</view>
									</view>
									<view class="item itemhover">
										<view class="num">{{item.sptgzcount}}</view>
										<view class="text">审批通过总任务</view>
									</view>
									<view class="item">
										<view class="num">{{item.dttjzcount}}</view>
										<view class="text">当日提交任务</view>
									</view>
									<view class="item">
										<view class="num">{{item.drjjzcount}}</view>
										<view class="text">当日拒绝任务</view>
									</view>
									<view class="item">
										<view class="num">{{item.drsptgzcount}}</view>
										<view class="text">审批通过任务</view>
									</view>
								</view>
							</view>
							<view class="bottomContent contentList" v-if="openShow">
								<view class="itembox">
									<view class="item itemhover" v-for="(ite,index) in showList" :key="index">
										<!-- <view class="num">{{item.tjzcount}}</view> -->
										<view class="text" @click="changeitem(ite.id,item.id)">
											<text :style="item.member_level == ite.id ?'color:red' :''">{{ite.title}}</text>
										</view>
									</view>
									<!-- <view class="item itemhover" >
										<view class="num">{{item.jjzcount}}</view>
										<view class="text">拒绝总任务</view>
									</view>
									<view class="item itemhover">
										<view class="num">{{item.sptgzcount}}</view>
										<view class="text">审批通过总任务</view>
									</view>
									<view class="item">
										<view class="num">{{item.dttjzcount}}</view>
										<view class="text">当日提交任务</view>
									</view>
									<view class="item">
										<view class="num">{{item.drjjzcount}}</view>
										<view class="text">当日拒绝任务</view>
									</view>
									<view class="item">
										<view class="num">{{item.drsptgzcount}}</view>
										<view class="text">审批通过任务</view>
									</view> -->
								</view>
							</view>
						</view>
					</mescroll-body>
				</block>
				<block v-else>
					<mescroll-body ref="mescrollRef" @down="downCallback" @up="upCallback"
					 :up = "upOption" :down="downOption">
						<view class="item2" v-for="(item,index) in taskList" :key="index">
							<view class="top">
								<view class="left">
									<image :src="$util.img(item.avatar[0])" mode=""></image>
									<text class="num">{{item.mobile}}</text>
								</view>
								<text class="time">{{item.update_time}}</text>
							</view>
							<view class="bottom">
								<text class="title">{{item.taskname}}</text>
								<text class="money">￥{{item.price}}元</text>
							</view>
						</view>
					</mescroll-body>
				</block>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import diyNavBar from '../../component/diy-nav/diy-navbar.vue'
	export default{
		components:{
			diyNavBar
		},
		mixins: [MescrollMixin],
		data(){
			return {
				list:{
					achievement_money:{
						title:'个人业绩',
						num:''
					},
					group_achievement_money:{
						title:'团队总业绩',
						num:''
					},
					group_person_count:{
						title:'团队人数',
						num:''
					}
				},
				tabsList:['直推','间推','任务记录'],
				indexJudge:0,
				// 滚动
				upOption:{
					page:{
						num:0,
						size:10
					},
					textNoMore:''
				},//上拉参数配置
				downOption:{
					auto:false,
					page:{
						num:0,
						size:10
					}
				},//下拉参数配置
				taskList:[],
				//任务数据展示
				contentList:{
					 tjzcount:{
						title:'提交总任务',
						num:''
					},
					jjzcount:{
						title:'拒绝总任务',
						num:''
					},
					sptgzcount:{
						title:'审批通过总任务',
						num:''
					},
					dttjzcount:{
						title:'当日提交任务',
						num:''
					},
					drjjzcount:{
						title:'当日拒绝任务',
						num:''
					},
					drsptgzcount:{
						title:'审批通过任务',
						num:''
					}
				},
				// 控制间推直推数据加载
				packupIndex:0,
				openShow:false,
				showList:[]
			}
		},
		onShow() {
			this.getMemberLevelList();
			this.$http.sendrequest('/member/Myteam',{},{
				tokenJudge:true
			}).then(res=>{
				if(res.code == 1){
					Object.keys(this.list).forEach((item,index)=>{
						this.list[item].num = res.data[item]; 
					})
					Object.keys(this.contentList).forEach((item,index)=>{
						this.contentList[item].num = res.data[item]; 
					})
				}
			})
		},
		methods:{
			getMemberLevelList(){
				this.$http.sendrequest('/member/MemberLevelList',{},{
					tokenJudge:true
				}).then(res=>{
					if(res.code == 1){
						this.showList = res.data;
					}
				})
			},
			changeitem(showid,id){
				this.$http.sendrequest('/member/Updatelevel',{
					member_level_id:showid,
					user_id:id
				},{
					tokenJudge:true
				}).then(res=>{
					if(res.code == 1){
						uni.showToast({
							title:res.msg,
							icon:"none"
						})
						this.openShow = false;
						this.mescroll.resetUpScroll();
					}else{
						uni.showToast({
							title:res.msg,
							icon:"none"
						})
						this.openShow = false;
						this.mescroll.resetUpScroll();
					}
				})
			},
			select(index){
				this.indexJudge = index;
				this.taskList = [];
				this.mescroll.resetUpScroll()
			},
			// 下拉刷新
			downCallback(page){
				this.mescroll.resetUpScroll()
			},
			//上拉加载
			upCallback(page){
				this.$http.sendrequest('/member/RecordStatus',{
					status:this.indexJudge + 1,
					num:page.num
				},{
					tokenJudge:true
				}).then(res=>{
					if(res.code == 1){
						if(page.num == 1) this.taskList = []; //如果是第一页需手动制空列表
						res.data.list = res.data.list.map(item=>{
							item.packupJudge = false;
							return item;
						})
						
						this.taskList = this.taskList.concat(res.data.list);
						this.mescroll.endBySize(res.data.list.length, res.data.count);
					}
				})
			},
			//控制展开
			packupSelect(index){
				this.packupIndex = index;
				this.taskList[index].packupJudge = !this.taskList[index].packupJudge;
			},
			packupSelect2(){
				this.openShow = !this.openShow;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.myteam{
		min-height: 100vh;
		background: $uni-content-background-color;
		font-family: SourceHanSansSC-medium;
		.teambox{
			background: #4689FF;
			height: 230rpx;
			padding-top:54rpx;
			box-sizing: border-box;
			display: flex;
			justify-content: space-around;
			margin-bottom: 34rpx;
			.item{
				display: flex;
				align-items: center;
				flex-direction: column;
				color: #FFFFFF;
				.money{
					font-weight: bold;
					font-size: 40rpx;
					line-height: 1.8;
				}
				.title{
					font-size: 28rpx;
				}
			}
		}
		
		.inputsearch{
			margin: 0 30rpx;
			border-radius: 64rpx;
			height: 64rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			background: #EFF2F7;
			input{
				text-align: center;
				width: 90%;
				height: 90%;
				font-size: 26rpx;
			}
		}
		.dieList{
			margin: 0 30rpx;
			background: #FFFFFF;
			border-radius: 24rpx;
			height: 984rpx;
			margin-top: 24rpx;
			padding-top: 10rpx;
			box-sizing: border-box;
			.tabrlist{
				display: flex;
				align-items: center;
				justify-content: space-between;
				.item{
					width: 230rpx;
					height: 88rpx;
					text-align: center;
					line-height: 88rpx;
					font-size: 26rpx;
					color: #999999;
				}
				.hovercolor{
					color: #4689FF;
					transition: all .2s;
				}
			}
			.scroll{
				height: calc(100% - 130rpx);
				.item{
					.itemBlock{
						min-height: 160rpx;
						display: flex;
						align-items: center;
						justify-content: space-between;
						margin: 0 30rpx;
						.left{
							display: flex;
							align-items: center;
							image{
								width: 80rpx;
								height: 80rpx;
								border-radius: 50%;
								margin-right: 26rpx;
							}
							.box{
								.num{
									font-size: 28rpx;
									display: flex;
									align-items: center;
									.txt{
										margin-left: 20rpx;
										font-size: 24rpx;
										color: #999999;
										display: flex;
										align-items: center;
										.icon-xiala1{
											font-size: 34rpx;
											margin-left: 4rpx;
										}
									}
								}
								.id{
									font-size: 24rpx;
									color: #666666;
									line-height: 1.8;
									margin-left: 4rpx;
								}
							}
						}
						.right{
							text-align: right;
							.title{
								color: #333333;
								font-size: 24rpx;
							}
							.money{
								font-size: 28rpx;
								color: #FF6F30;
								line-height: 1.8;
								font-weight: bold;
							}
						}
					}
				}
				.item2{
					height: 240rpx;
					padding: 40rpx 30rpx;
					box-sizing: border-box;
					.top{
						display: flex;
						align-items: center;
						justify-content: space-between;
						margin-bottom: 40rpx;
						.left{
							display: flex;
							align-items: center;
							image{
								width: 80rpx;
								height: 80rpx;
								border-radius: 50%;
								margin-right: 24rpx;
							}
							.num{
								font-size: 28rpx;
								font-weight: bold;
							}
						}
						.time{
							font-size: 24rpx;
							color: #999999;
						}
					}
					.bottom{
						display: flex;
						align-items: center;
						justify-content: space-between;
						font-size: 26rpx;
						.money{
							font-size: 28rpx;
							font-weight: bold;
							color: #FF6F30;
						}
					}
				}
			}
		}
	}
	/deep/ ::-webkit-scrollbar{
		width: 0;
	}
	//任务数据展示
	.contentList{
		margin: 28rpx 30rpx;
		background: #FFFFFF;
		border-radius: 24rpx;
		padding: 42rpx 34rpx;
		box-sizing: border-box;
		.title{
			font-size:28rpx;
			font-weight:bold;
		}
		.itembox{
			display: flex;
			align-items: center;
			flex-wrap: wrap;
			justify-content: space-between;
			.item{
				width: 182rpx;
				margin:46rpx 0 0 0;
				display: flex;
				align-items: center;
				flex-direction: column;
				.num{
					font-size:40rpx;
					font-weight: bold;
					color: #4689FF;
					text-align: center;
				}
				.text{
					font-size: 26rpx;
					margin-top: 10rpx;
				}
			}
		}
		
		.item:nth-child(3n){
			margin-right:0;
		}
	}
	.bottomContent{
		margin: 0;
		padding-top:0 ;
		.itemhover{
			margin-top: 0 !important;
			.num{
				color: #FF6F30 !important;
			}
		}
		
	}
</style>
